﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.ScriptableCullingParameters
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Parameters that configure a culling operation in the Scriptable Render Pipeline.</para>
  /// </summary>
  [UsedByNativeCode]
  public struct ScriptableCullingParameters : IEquatable<ScriptableCullingParameters>
  {
    private int m_IsOrthographic;
    private LODParameters m_LODParameters;
    private const int k_MaximumCullingPlaneCount = 10;
    /// <summary>
    ///   <para>Maximum amount of culling planes that can be specified.</para>
    /// </summary>
    public static readonly int maximumCullingPlaneCount = 10;
    internal unsafe fixed byte m_CullingPlanes[160];
    private int m_CullingPlaneCount;
    private uint m_CullingMask;
    private ulong m_SceneMask;
    private const int k_LayerCount = 32;
    /// <summary>
    ///   <para>The amount of layers available.</para>
    /// </summary>
    public static readonly int layerCount = 32;
    internal unsafe fixed float m_LayerFarCullDistances[32];
    private int m_LayerCull;
    private Matrix4x4 m_CullingMatrix;
    private Vector3 m_Origin;
    private float m_ShadowDistance;
    private float m_ShadowNearPlaneOffset;
    private CullingOptions m_CullingOptions;
    private ReflectionProbeSortingCriteria m_ReflectionProbeSortingCriteria;
    private CameraProperties m_CameraProperties;
    private float m_AccurateOcclusionThreshold;
    private int m_MaximumPortalCullingJobs;
    private const int k_CullingJobCountLowerLimit = 1;
    private const int k_CullingJobCountUpperLimit = 16;
    private Matrix4x4 m_StereoViewMatrix;
    private Matrix4x4 m_StereoProjectionMatrix;
    private float m_StereoSeparationDistance;
    private int m_maximumVisibleLights;
    private bool m_ConservativeEnclosingSphere;
    private int m_NumIterationsEnclosingSphere;

    /// <summary>
    ///   <para>This parameter controls how many visible lights are allowed.</para>
    /// </summary>
    public int maximumVisibleLights
    {
      get => this.m_maximumVisibleLights;
      set => this.m_maximumVisibleLights = value;
    }

    /// <summary>
    ///   <para>This property enables a conservative method for calculating the size and position of the minimal enclosing sphere around the frustum cascade corner points for shadow culling.</para>
    /// </summary>
    public bool conservativeEnclosingSphere
    {
      get => this.m_ConservativeEnclosingSphere;
      set => this.m_ConservativeEnclosingSphere = value;
    }

    /// <summary>
    ///   <para></para>
    /// </summary>
    public int numIterationsEnclosingSphere
    {
      get => this.m_NumIterationsEnclosingSphere;
      set => this.m_NumIterationsEnclosingSphere = value;
    }

    /// <summary>
    ///   <para>Number of culling planes to use.</para>
    /// </summary>
    public int cullingPlaneCount
    {
      get => this.m_CullingPlaneCount;
      set
      {
        this.m_CullingPlaneCount = value >= 0 && value <= 10 ? value : throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be at least 0 and less than {2}", (object) nameof (value), (object) value, (object) 10));
      }
    }

    /// <summary>
    ///   <para>Is the cull orthographic.</para>
    /// </summary>
    public bool isOrthographic
    {
      get => Convert.ToBoolean(this.m_IsOrthographic);
      set => this.m_IsOrthographic = Convert.ToInt32(value);
    }

    /// <summary>
    ///   <para>LODParameters for culling.</para>
    /// </summary>
    public LODParameters lodParameters
    {
      get => this.m_LODParameters;
      set => this.m_LODParameters = value;
    }

    /// <summary>
    ///   <para>The mask for the culling operation.</para>
    /// </summary>
    public uint cullingMask
    {
      get => this.m_CullingMask;
      set => this.m_CullingMask = value;
    }

    /// <summary>
    ///   <para>The matrix for the culling operation.</para>
    /// </summary>
    public Matrix4x4 cullingMatrix
    {
      get => this.m_CullingMatrix;
      set => this.m_CullingMatrix = value;
    }

    /// <summary>
    ///   <para>Position for the origin of the cull.</para>
    /// </summary>
    public Vector3 origin
    {
      get => this.m_Origin;
      set => this.m_Origin = value;
    }

    /// <summary>
    ///   <para>Shadow distance to use for the cull.</para>
    /// </summary>
    public float shadowDistance
    {
      get => this.m_ShadowDistance;
      set => this.m_ShadowDistance = value;
    }

    /// <summary>
    ///   <para>Offset to apply to the near camera plane when performing shadow map rendering.</para>
    /// </summary>
    public float shadowNearPlaneOffset
    {
      get => this.m_ShadowNearPlaneOffset;
      set => this.m_ShadowNearPlaneOffset = value;
    }

    /// <summary>
    ///   <para>Flags to configure a culling operation in the Scriptable Render Pipeline.</para>
    /// </summary>
    public CullingOptions cullingOptions
    {
      get => this.m_CullingOptions;
      set => this.m_CullingOptions = value;
    }

    /// <summary>
    ///   <para>Reflection Probe Sort options for the cull.</para>
    /// </summary>
    public ReflectionProbeSortingCriteria reflectionProbeSortingCriteria
    {
      get => this.m_ReflectionProbeSortingCriteria;
      set => this.m_ReflectionProbeSortingCriteria = value;
    }

    /// <summary>
    ///   <para>Camera Properties used for culling.</para>
    /// </summary>
    public CameraProperties cameraProperties
    {
      get => this.m_CameraProperties;
      set => this.m_CameraProperties = value;
    }

    /// <summary>
    ///   <para>The view matrix generated for single-pass stereo culling.</para>
    /// </summary>
    public Matrix4x4 stereoViewMatrix
    {
      get => this.m_StereoViewMatrix;
      set => this.m_StereoViewMatrix = value;
    }

    /// <summary>
    ///   <para>The projection matrix generated for single-pass stereo culling.</para>
    /// </summary>
    public Matrix4x4 stereoProjectionMatrix
    {
      get => this.m_StereoProjectionMatrix;
      set => this.m_StereoProjectionMatrix = value;
    }

    /// <summary>
    ///   <para>Distance between the virtual eyes.</para>
    /// </summary>
    public float stereoSeparationDistance
    {
      get => this.m_StereoSeparationDistance;
      set => this.m_StereoSeparationDistance = value;
    }

    /// <summary>
    ///   <para>This parameter determines query distance for occlusion culling.</para>
    /// </summary>
    public float accurateOcclusionThreshold
    {
      get => this.m_AccurateOcclusionThreshold;
      set => this.m_AccurateOcclusionThreshold = Mathf.Max(-1f, value);
    }

    /// <summary>
    ///   <para>This parameter controls how many active jobs contribute to occlusion culling.</para>
    /// </summary>
    public int maximumPortalCullingJobs
    {
      get => this.m_MaximumPortalCullingJobs;
      set
      {
        this.m_MaximumPortalCullingJobs = value >= 1 && value <= 16 ? value : throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be in range {2} to {3}", (object) nameof (maximumPortalCullingJobs), (object) this.maximumPortalCullingJobs, (object) 1, (object) 16));
      }
    }

    /// <summary>
    ///   <para>The lower limit to the value ScriptableCullingParameters.maximumPortalCullingJobs.</para>
    /// </summary>
    public static int cullingJobsLowerLimit => 1;

    /// <summary>
    ///   <para>The upper limit to the value ScriptableCullingParameters.maximumPortalCullingJobs.</para>
    /// </summary>
    public static int cullingJobsUpperLimit => 16;

    /// <summary>
    ///   <para>Get the distance for the culling of a specific layer.</para>
    /// </summary>
    /// <param name="layerIndex"></param>
    public unsafe float GetLayerCullingDistance(int layerIndex)
    {
      if (layerIndex < 0 || layerIndex >= 32)
        throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be at least 0 and less than {2}", (object) nameof (layerIndex), (object) layerIndex, (object) 32));
      fixed (float* numPtr = this.m_LayerFarCullDistances)
        return numPtr[layerIndex];
    }

    /// <summary>
    ///   <para>Set the distance for the culling of a specific layer.</para>
    /// </summary>
    /// <param name="layerIndex"></param>
    /// <param name="distance"></param>
    public unsafe void SetLayerCullingDistance(int layerIndex, float distance)
    {
      if (layerIndex < 0 || layerIndex >= 32)
        throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be at least 0 and less than {2}", (object) nameof (layerIndex), (object) layerIndex, (object) 32));
      fixed (float* numPtr = this.m_LayerFarCullDistances)
        numPtr[layerIndex] = distance;
    }

    /// <summary>
    ///   <para>Fetch the culling plane at the given index.</para>
    /// </summary>
    /// <param name="index"></param>
    public unsafe Plane GetCullingPlane(int index)
    {
      if (index < 0 || index >= this.cullingPlaneCount)
        throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be at least 0 and less than {2}", (object) nameof (index), (object) index, (object) this.cullingPlaneCount));
      fixed (byte* numPtr = this.m_CullingPlanes)
        return *(Plane*) (numPtr + ((IntPtr) index * sizeof (Plane)).ToInt64());
    }

    /// <summary>
    ///   <para>Set the culling plane at a given index.</para>
    /// </summary>
    /// <param name="index"></param>
    /// <param name="plane"></param>
    public unsafe void SetCullingPlane(int index, Plane plane)
    {
      if (index < 0 || index >= this.cullingPlaneCount)
        throw new ArgumentOutOfRangeException(string.Format("{0} was {1}, but must be at least 0 and less than {2}", (object) nameof (index), (object) index, (object) this.cullingPlaneCount));
      fixed (byte* numPtr = this.m_CullingPlanes)
        *(Plane*) (numPtr + ((IntPtr) index * sizeof (Plane)).ToInt64()) = plane;
    }

    public bool Equals(ScriptableCullingParameters other)
    {
      for (int layerIndex = 0; layerIndex < 32; ++layerIndex)
      {
        if (!this.GetLayerCullingDistance(layerIndex).Equals(other.GetLayerCullingDistance(layerIndex)))
          return false;
      }
      for (int index = 0; index < this.cullingPlaneCount; ++index)
      {
        if (!this.GetCullingPlane(index).Equals((object) other.GetCullingPlane(index)))
          return false;
      }
      return this.m_IsOrthographic == other.m_IsOrthographic && this.m_LODParameters.Equals(other.m_LODParameters) && this.m_CullingPlaneCount == other.m_CullingPlaneCount && (int) this.m_CullingMask == (int) other.m_CullingMask && (long) this.m_SceneMask == (long) other.m_SceneMask && this.m_LayerCull == other.m_LayerCull && this.m_CullingMatrix.Equals(other.m_CullingMatrix) && this.m_Origin.Equals(other.m_Origin) && this.m_ShadowDistance.Equals(other.m_ShadowDistance) && this.m_ShadowNearPlaneOffset.Equals(other.m_ShadowNearPlaneOffset) && this.m_CullingOptions == other.m_CullingOptions && this.m_ReflectionProbeSortingCriteria == other.m_ReflectionProbeSortingCriteria && this.m_CameraProperties.Equals(other.m_CameraProperties) && this.m_AccurateOcclusionThreshold.Equals(other.m_AccurateOcclusionThreshold) && this.m_StereoViewMatrix.Equals(other.m_StereoViewMatrix) && this.m_StereoProjectionMatrix.Equals(other.m_StereoProjectionMatrix) && this.m_StereoSeparationDistance.Equals(other.m_StereoSeparationDistance) && this.m_maximumVisibleLights == other.m_maximumVisibleLights && this.m_ConservativeEnclosingSphere == other.m_ConservativeEnclosingSphere && this.m_NumIterationsEnclosingSphere == other.m_NumIterationsEnclosingSphere;
    }

    public override bool Equals(object obj)
    {
      return obj != null && obj is ScriptableCullingParameters other && this.Equals(other);
    }

    public override int GetHashCode()
    {
      return (((((((((int) ((ReflectionProbeSortingCriteria) ((int) ((CullingOptions) ((((((((((this.m_IsOrthographic * 397 ^ this.m_LODParameters.GetHashCode()) * 397 ^ this.m_CullingPlaneCount) * 397 ^ (int) this.m_CullingMask) * 397 ^ this.m_SceneMask.GetHashCode()) * 397 ^ this.m_LayerCull) * 397 ^ this.m_CullingMatrix.GetHashCode()) * 397 ^ this.m_Origin.GetHashCode()) * 397 ^ this.m_ShadowDistance.GetHashCode()) * 397 ^ this.m_ShadowNearPlaneOffset.GetHashCode()) * 397) ^ this.m_CullingOptions) * 397) ^ this.m_ReflectionProbeSortingCriteria) * 397 ^ this.m_CameraProperties.GetHashCode()) * 397 ^ this.m_AccurateOcclusionThreshold.GetHashCode()) * 397 ^ this.m_MaximumPortalCullingJobs.GetHashCode()) * 397 ^ this.m_StereoViewMatrix.GetHashCode()) * 397 ^ this.m_StereoProjectionMatrix.GetHashCode()) * 397 ^ this.m_StereoSeparationDistance.GetHashCode()) * 397 ^ this.m_maximumVisibleLights) * 397 ^ this.m_ConservativeEnclosingSphere.GetHashCode()) * 397 ^ this.m_NumIterationsEnclosingSphere.GetHashCode();
    }

    public static bool operator ==(
      ScriptableCullingParameters left,
      ScriptableCullingParameters right)
    {
      return left.Equals(right);
    }

    public static bool operator !=(
      ScriptableCullingParameters left,
      ScriptableCullingParameters right)
    {
      return !left.Equals(right);
    }
  }
}
